import React from 'react';
import PropType from 'prop-types';
import {withRouter} from 'react-router-dom';
import {Card, WingBlank} from 'antd-mobile';

@withRouter
class UserCard extends React.Component {

    handleClick(v) {
        this.props.history.push(`/chat/${v._id}`)
    }

    render() {
        const Header = Card.Header;
        const Body = Card.Body;
        return (
            <WingBlank>
                {
                    this.props.userList.map((v) => (
                        v.avatar ? (<Card
                            key={v._id}
                            onClick={()=> this.handleClick(v)}
                        >
                            <Header
                                title={v.user}
                                thumb={require(`../images/${v.avatar}.png`)}
                                extra={(<span>{v.title}</span>)}
                            >
                            </Header>
                            <Body>
                            {v.type === 'boss' ? <div>公司: {v.company}</div> : null}

                            {v.desc.split('\n').map((d, index) => (
                                <div key={index}>{d}</div>
                            ))}
                            {v.type === 'boss' ? <div>薪资: {v.money}</div> : null}
                            </Body>
                        </Card>) : null
                    ))
                }
            </WingBlank>
        )
    }
}

UserCard.propTypes = {
    userList: PropType.array.isRequired
};

export default UserCard;
